public class RobotRightHand extends Robot
{	
	public RobotRightHand(Labyrinthe lab)
	{
		super(lab, new int[]{Labyrinthe.UP, Labyrinthe.RIGHT, Labyrinthe.DOWN, Labyrinthe.LEFT});
	}
	
	public RobotRightHand(Labyrinthe lab, int[] prefs)
	{
		super(lab, prefs);
	}

	public int findExit()
	{
		int dir=0, ct=0, ct2;
		while (!laby.isWall(preferences[(dir+1) % 4]))
			dir++;
		while (!laby.isExit())
		{
			ct++;
			if (ct>50) return -42; //FIXME
			laby.go(preferences[dir]);
			switch (preferences[dir])
			{
				case Labyrinthe.UP: System.out.println("UP"); break;
				case Labyrinthe.RIGHT: System.out.println("RIGHT"); break;
				case Labyrinthe.DOWN: System.out.println("DOWN"); break;
				case Labyrinthe.LEFT: System.out.println("LEFT"); break;
			}
			if (!laby.isWall(preferences[(dir+1) % 4]) || laby.isWall(preferences[dir]))
			{
				ct2 = 0;
				do
				{
					dir = (dir+1) % 4;
					ct2++;
				} while (laby.isWall(preferences[dir]) && ct2<5);
				if (ct2 == 5) return -1; //no way
			}
		}
		return ct;
	}
	
}
